package thread.reentrantreadwritelock;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class ReentrantReadWriteLockTest {
    ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
    Lock readLock = reentrantReadWriteLock.readLock();
    Lock writeLock = reentrantReadWriteLock.writeLock();




    public void writeDate() throws InterruptedException {
        System.out.println("写入数据：当前线程->"+Thread.currentThread().getName());

    }

    public void readDate() throws InterruptedException {
        try {
            readLock.lock();
            System.out.println("读取数据:当前线程->"+Thread.currentThread().getName());
        }catch (Exception e){
             throw e;
        }
        finally {
            readLock.unlock();
        }
    }
}
